package com.patrol.patrol.ui.appear;

import android.os.Bundle;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.google.android.material.tabs.TabLayout;
import com.patrol.patrol.R;
import com.patrol.patrol.ui.BaseActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

@Route(path = "/app/TabActivity")
public class TabActivity extends BaseActivity {
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tab_layout)
    TabLayout mTabLayout;
    @BindView(R.id.viewpager)
    ViewPager mViewPager;

    private PagerAdapter mPagerAdapter;
    private String[] titles = {"事件上报","数据编辑"};
    private List<Fragment> fragments;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tab);
        ButterKnife.bind(this);

        tvTitle.setText("事件上报");

        initViewPagerFragment();

    }

    private void initViewPagerFragment() {
        mPagerAdapter = new PagerAdapter(getSupportFragmentManager());
        fragments = new ArrayList<>();
        for (int i = 0; i < titles.length; i++) {
            fragments.add(FragmentFactory.createFragment(i));
        }
        mPagerAdapter.setTitles(titles);
        mPagerAdapter.setFragments(fragments);
        mViewPager.setAdapter(mPagerAdapter);
        //将TabLayout和ViewPager绑定
        mTabLayout.setupWithViewPager(mViewPager);
        mTabLayout.setTabMode(TabLayout.MODE_FIXED);
        //mTabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
    }
}
